import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: '',
    meta: { title: '首页', requiresAuth: false },

    redirect: '/h5',
    children: [
      {
        path: 'h5',
        name: 'h5',
        meta: { title: '首页', requiresAuth: false },
        component: () => import('@/views/layout/index.vue'),
        redirect: '/h5/home',
        children: [
          {
            path: 'home',
            name: '',
            meta: { title: '首页', requiresAuth: false },
            component: () => import('@/views/home/index.vue'),
            children: []
          },
          {
            path: 'classify/:title/:id',
            name: 'classify',
            meta: { title: '分类', requiresAuth: false },
            component: () => import('@/views/home/classify.vue'),
            children: []
          },
          {
            path: 'details/:title/:id',
            name: 'details',
            meta: { title: '详情', requiresAuth: false },
            component: () => import('@/views/home/details.vue'),
          },
          {
            path: 'reservation',
            name: '',
            meta: { title: '预约', requiresAuth: false },
            component: () => import('@/views/reservation/index.vue'),
            children: []
          },
          {
            path: 'my',
            name: '我的',
            meta: { title: '我的', requiresAuth: false },
            component: () => import('@/views/my/index.vue'),
            children: []
          }
        ]
      }
    ]

  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constantRoutes
})

// 路由跳转前的监听操作
router.beforeEach((to, _from, next) => {
  // 修改title
  document.title = to.meta.title + ' - 九五装饰产品库';
  next()
})

/**
 * 进度条完成
 */
router.afterEach(() => {
})
export default router